//
//  TroopForm.cpp
//  fingeradvanture
//
//  Created by shuaibincheng on 16/5/7.
//
//
 
#include "TroopForm.hpp"
#include "MonsterDen.hpp"
#include "SingleTroopForm.hpp"
#include "LineTroopForm.hpp"
#include "CrossTroopForm.hpp"
#include "SquareTroopForm.hpp"
#include "HexagonTroopForm.hpp"

TroopForm *TroopForm::getTroopFormByType(TroopFormType type)
{
    switch(type)
    {
        case TROOP_SINGLE_FORM:
            return new SingleTroopForm;
        case TROOP_LINE_FORM:
            return new LineTroopForm;
        case TROOP_CROSS_FORM:
            return new CrossTroopForm;
        case TROOP_SQUARE_FORM:
            return new SquareTroopForm;
        case TROOP_HEXAGON_FORM:
            return new HexagonTroopForm;
        default:
            return 0;
    }
}

int TroopForm::getMaxNumOfMonsterTypes() const
{
    return maxNumOfMonsterTypes;
}

TroopForm::TroopForm(int numOfType, int maxNumOfMonster, int minNumOfMonster)
{
    this->maxNumOfMonsterTypes = numOfType;
    this->maxNumOfMonster = maxNumOfMonster;
    this->minNumOfMonster = minNumOfMonster;
    
    this->style = NULL;
    this->members = new Vector<Node *>;
}

void TroopForm::join(cocos2d::Node *monster)
{
    members->pushBack(monster);
}

void TroopForm::group()
{
    //子类需要实现
}

void TroopForm::train()
{
    
}

float TroopForm::marginLeft()
{
    auto first = members->at(0);
    auto position = first->getPosition();
    
    auto screenWidth = (Director::getInstance()->getVisibleSize()).width;
    
    auto leftX = 0.0f;
    if(troopVisibleSize.width > screenWidth)
    {
        leftX = (screenWidth - troopVisibleSize.width) / 2;
    }
    else
    {
        leftX = 0.0f;
    }
    auto anchorPoint = first->getAnchorPoint();
    return (position.x - (anchorPoint.x) * first->getContentSize().width) - leftX;
}

float TroopForm::marginRight()
{
    auto last = members->at(members->size() - 1);
    auto position = last->getPosition();
    
    auto screenWidth = (Director::getInstance()->getVisibleSize()).width;
    
    auto rightX = 0.0f;
    if(troopVisibleSize.width > screenWidth)
    {
        rightX = screenWidth + (troopVisibleSize.width - screenWidth) / 2;
    }
    else
    {
        rightX = screenWidth;
    }
    auto anchorPoint = last->getAnchorPoint();
    return -(position.x + (1 - anchorPoint.x) * last->getContentSize().width) + rightX;
}

int TroopForm::numOfMonsterForType(const MonsterType &type)
{
    //子类需要实现
    return 0;
}

std::vector<TroopStyleType> TroopForm::allowedTroopStyles()
{
    return std::vector<TroopStyleType>();
}
std::vector<TroopActionStyle> TroopForm::allowedTroopActionStyle()
{
    return std::vector<TroopActionStyle>();
}
